﻿using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Specialized;
using System.Xml.Linq;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using AjaxControlToolkit;
using System.Collections.Generic;

/// <summary>
///DepartmentService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
[System.Web.Script.Services.ScriptService]
public class DepartmentService : System.Web.Services.WebService
{

    public DepartmentService()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod]
    public CascadingDropDownNameValue[] GetDepartments(string knownCategoryValues, string category)
    {
        string sql = "(Right(DepartmentID, 3) = '000') AND State = 0";
        List<DepartmentInfo> departments = Department.GetList(sql);
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        foreach (DepartmentInfo department in departments)
        {
            values.Add(new CascadingDropDownNameValue(department.ShortName, department.DepartmentID));
        }
        return values.ToArray();
    }
    [WebMethod]
    public CascadingDropDownNameValue[] GetUnits(string knownCategoryValues, string category)
    {
        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        string departmentID = kv["Department"].ToString();
        string sql = "(SUBSTRING(DepartmentID, 1, 4) = '" + departmentID.Substring(0, 4) + "') AND State = 0";
        List<DepartmentInfo> departments = Department.GetList(sql);
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        foreach (DepartmentInfo department in departments)
        {
            values.Add(new CascadingDropDownNameValue(department.ShortName, department.DepartmentID));
        }
        return values.ToArray();
    }
    [WebMethod]
    public CascadingDropDownNameValue[] GetUsers(string knownCategoryValues, string category)
    {
        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        string departmentID = kv["Unit"].ToString();
        string sql = "DepartmentID = '" + departmentID + "') AND State = 0)";
        List<UserInfo> users = Yipusoft.Account.BLL.User.GetList(sql);
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        foreach (UserInfo user in users)
        {
            values.Add(new CascadingDropDownNameValue(user.UserName, user.UserID));
        }
        return values.ToArray();
    }

}

